home *** CD-ROM | disk | FTP | other *** search
- //: C08:ConstInitialization.cpp
- // From Thinking in C++, 2nd Edition
- // Available at http://www.BruceEckel.com
- // (c) Bruce Eckel 1999
- // Copyright notice in Copyright.txt
- // Initializing const in classes
- #include <iostream>
- using namespace std;
-
- class Fred {
- const int size;
- public:
- Fred(int sz);
- void print();
- };
-
- Fred::Fred(int sz) : size(sz) {}
- void Fred::print() { cout << size << endl; }
-
- int main() {
- Fred a(1), b(2), c(3);
- a.print(), b.print(), c.print();
- } ///:~
-